import { Component } from '@angular/core';
import { NavController, NavParams, ItemSliding } from 'ionic-angular';
import { User } from '../../providers/login-data/user';
import { Observable } from 'rxjs/Observable';
import { UserSettingProvider } from '../../providers/user-setting/user-setting';
import { HttpHeaders, HttpClient, HttpParams } from '@angular/common/http';



@Component({
  selector: 'page-department-framwork',
  templateUrl: 'department-framwork.html',
})
export class DepartmentFramworkPage {
   flag:boolean;
   leval:string;
  user: User[] = [];
  discipline_1 = new Array();  //纪律
  discipline_2 = new Array();  //纪律
  study_1 = new Array();       //学习
  study_2 = new Array();       //学习
  organize_1 = new Array();    //组织
  organize_2 = new Array();    //组织
  branch_1 = new Array();      //支部
  branch_2 = new Array();      //支部
  advertise_1 = new Array();     //宣传
  advertise_2 = new Array();     //宣传
  // private num: number = 5;//每页显示记录数
  // private curPage: number = 1;
  // private hasMore: boolean = true;

  public architecture: string = 'system'; //默认显示


  constructor(public http: HttpClient,
    public navCtrl: NavController,
    public navParams: NavParams,
    public userSettingProvider: UserSettingProvider
    // userSettingProvider: UserSettingProvider,


  ) {
  }
  /**
   * 获取用户数据
   * @returns {Observable<User[]>}  用户数据集合
   */


  ionViewDidLoad() {
    this.userSettingProvider.getUsers().subscribe(user => {
      this.user = user;
      // console.log(this.user);
      let long = this.user.length;
      // console.log(long);
      this.leval = localStorage.getItem("leval");
     if (this.leval == '0') {
      this.flag = false;
    } else {
      this.flag = true;
    }
      
      for (let i = 0; i < long; i++) {
        if (this.user[i].belong == "第一支部" && this.user[i].position == "纪律委员") {
          this.discipline_1[0] = this.user[i].name;
          this.discipline_1[1] = this.user[i].mobilePhoneNumber;
        } else if (this.user[i].belong == "第二支部" && this.user[i].position == "纪律委员") {
          this.discipline_2[0] = this.user[i].name;
          this.discipline_2[1] = this.user[i].mobilePhoneNumber;
        }else if (this.user[i].belong == "第一支部" && this.user[i].position == "学习委员") {
          this.study_1[0] = this.user[i].name;
          this.study_1[1] = this.user[i].mobilePhoneNumber;
        }else if (this.user[i].belong == "第二支部" && this.user[i].position == "学习委员") {
          this.study_2[0] = this.user[i].name;
          this.study_2[1] = this.user[i].mobilePhoneNumber;
        }else if (this.user[i].belong == "第一支部" && this.user[i].position == "组织委员") {
          this.organize_1[0] = this.user[i].name;
          this.organize_1[1] = this.user[i].mobilePhoneNumber;
        }else if (this.user[i].belong == "第二支部" && this.user[i].position == "组织委员") {
          this.organize_2[0] = this.user[i].name;
          this.organize_2[1] = this.user[i].mobilePhoneNumber;
        }else if (this.user[i].belong == "第一支部" && this.user[i].position == "支部书记") {
          this.branch_1[0] = this.user[i].name;
          this.branch_1[1] = this.user[i].mobilePhoneNumber;
        }else if (this.user[i].belong == "第二支部" && this.user[i].position == "支部书记") {
          this.branch_2[0] = this.user[i].name;
          this.branch_2[1] = this.user[i].mobilePhoneNumber;
        }else if (this.user[i].belong == "第一支部" && this.user[i].position == "宣传委员") {
          this.advertise_1[0] = this.user[i].name;
          this.advertise_1[1] = this.user[i].mobilePhoneNumber;
        }else if (this.user[i].belong == "第二支部" && this.user[i].position == "宣传委员") {
          this.advertise_2[0] = this.user[i].name;
          this.advertise_2[1] = this.user[i].mobilePhoneNumber;
        }
      }
      
    });

      
  }
  // 删除待办事项
  removeUser(slidingItem: ItemSliding, use: User){
    // use.status ='removed';
    let index = this.user.indexOf(use);
    if (index > -1) {
      this.user.splice(index,1);
    }
    this.userSettingProvider.deleteUser(use).subscribe();
    slidingItem.close();
    console.log("sdfdf");
    
  }
  // getUsers(): void {
  //   this.userSettingProvider.getUsers().subscribe(users => {
  //   this.user = users;
  //     // 保留原有数据
  //   });
  // }


}